import type { ForumPost, PostDetail, PublishForm, SearchParams } from '@/types/forum'
import { sendRequest } from '@/utils/http'

// 获取帖子列表（分页）
export const getForumPostsAPI = (params: SearchParams) => {
  return sendRequest<ForumPost[]>({ //响应返回值是ForumPost[]
    url: '/server-interview/forum/list',
    method: 'GET',
    data: params
  })
}

// 发布帖子
export const publishForumPostAPI = (form: PublishForm) => {
  return sendRequest<string>({ //响应返回值是string
    url: '/server-interview/forum/publish',
    method: 'POST',
    data: form
  })
} 

// 获取帖子详情
export const getForumPostDetailAPI = (id: number) => {
    return sendRequest<PostDetail>({ //响应返回值是ForumPost
      url: `/server-interview/forum/detail/`,
      method: 'GET',
      data: {
        id: id
      }
    })
  }

//删除帖子
export const deleteForumPostAPI = (id: number) => {
  return sendRequest<string>({ //响应返回值是string
    url: `/server-interview/forum/delete/`,
    method: 'DELETE',
    data: {
      id: id
    }
  })
}

//更新帖子
export const updateForumPostAPI = (id: number, form: PublishForm) => {
  return sendRequest<string>({ //响应返回值是string
    url: `/server-interview/forum/update/`,
    method: 'PUT',
    data: {
      id: id,
      ...form
    }
  })
}